/**
 * Description:
 *
 * @author      Eden
 * @datetime    2017/1/2 01:18
 * @copyright   WuHan HuQi Technology Co.,Ltd.
 * @url         http://cnhuqi.com
 */

(function () {

    "use strict";


    var api = {
        getCommentsDetail: '/api/comments/getComments'
    };
    sm.controller('wx-goods-comments-detail-controller', ['$scope', '$http', 'Modal', 'Toast', function ($scope, $http, Modal, Toast) {

        var goodsId = GetQueryString('goodsId');

        $scope.detail = [];
        $scope.total = 0;
        $scope.nextPage = false;
        $scope.nowPage = 1;

        $scope.getComments = function () {
            doGetPage();
        };

        function doGetPage() {
            $http.get(api.getCommentsDetail, {
                params: {
                    page: $scope.nowPage,
                    goodsId: goodsId
                }
            }).success(function (res) {
                if (res.state) {
                    $scope.nextPage = res.data.nextPage;
                    $scope.total = res.data.total;
                    // $scope.detail = res.data.data;
                    appendData($scope.detail, res.data.data);
                }
            });
        }

        function appendData (nowData, appendData) {
            angular.forEach(appendData, function (val) {
                nowData.unshift(val)
            });
        }

        $scope.loadMore = function () {
            if ($scope.nextPage) {
                $scope.nowPage += 1;
            }
            doGetPage();
        };

        $scope.getComments();

    }]);

})();